<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>OCR异常订单检索</title>
		<script type="text/javascript">
		var index=0;
		var tempOrdeno="";
		var tempOrdenoItemId=0;
		var normalIndex=0;
		var ordenoId="";
		function setOrdeno(item){
		  ordenoId=item;
		  $("#ordenoItems").html("");
		}
	$(function() {
		$("#nowDate").datepicker({format :  'yyyy-mm-dd'});
	});

	$(function() {
	    $("#nowDate").datepicker().on('changeDate',function() {
			window.location.href = "${ctx}/ediOrderSource/searchCheck/"+$("#nowDate").val();
	    });
	});
	
	function deleteOrdeno(item){
	  $.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/deleteOrdeno',
			data :  'id='+item,
			dataType :  'json',
			success :  function(data) {
			  if(data.status=="1"){
			      $("#ordeno_"+item).hide();
			       var ordenoNumber=$("#ordenoNumber").html();
			       ordenoNumber=Number(ordenoNumber);
			       $("#ordenoNumber").html(ordenoNumber-1);
			  }
			    $("#message").show();
				$("#content").html(data.content);
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	function deleteOrdenoItem(item){
	  $.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/deleteOrdenoItem',
			data :  'id='+item,
			dataType :  'json',
			success :  function(data) {
			  if(data.status=="1"){
			      $("#ordenoItem_"+item).hide();
			      var ordenoItemNumber=$("#ordenoItemNumber").html();
			       ordenoItemNumber=Number(ordenoItemNumber);
			       $("#ordenoItemNumber").html(ordenoItemNumber-1);
			  }
			    $("#message").show();
				$("#content").html(data.content);
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	
	function updateOrdeno(){
	var ordeno=$("#ordeno").val();
	var addres=$("#addres").val();
	var provna=$("#provna").val();
	var provco=$("#provco").val();
	var cityna=$("#cityna").val();
	var cityco=$("#cityco").val();
	var distna=$("#distna").val();
	var distco=$("#distco").val();
	var postco=$("#postco").val();
	var bunick=$("#bunick").val();
	var recena=$("#recena").val();
	var mobile=$("#mobile").val();
	var teleph=$("#teleph").val();
	var shopna=$("#shopna").val();
	var waybillNo=$("#waybillNo").val();
	var ordenoMessage=$("#ordenoMessage").val();
	var customerOrdeno=$("#customerOrdeno").val();
	  $.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/updateOrdeno',
			data :  'ordeno='+ordeno+'&addres='+addres+'&provna='+provna+'&provco='+provco+'&cityna='+cityna+'&cityco='+cityco+
			       '&distna='+distna+'&distco='+distco+'&postco='+postco+'&bunick='+bunick+'&recena='+recena+'&mobile='+mobile+'&teleph='+teleph+
			       '&shopna='+shopna+'&ordenoMessage='+ordenoMessage+'&waybillNo='+waybillNo+'&id='+ordenoId+'&customerOrdeno='+customerOrdeno,
			dataType :  'json',
			success :  function(data) {
			    $("#message").show();
				$("#content").html(data.content);
				window.location.href = "${ctx}/ediOrderSource/searchCheck/"+$("#nowDate").val();
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	function getAjaxOrdersCheck(id) {
	        ordenoId=id; 
		var tempString = "";
		$.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/detailed',
			data :  'id=' + id,
			dataType :  'json',
			success :  function(data) {
				if (data.status == "1") {
				 var addres=data.content.addres.replace(/[ ]/g,"");
					tempString += "<tr><th>订单编号</th><td><input type=\"text\" id=\"ordeno\" value="+ data.content.ordeno + "></td></tr>"
					        +"<tr><th>商家订单号</th><td><input type=\"text\" id=\"customerOrdeno\" value="+ data.content.customerOrdeno + "></td></tr>"
					        +"<tr><th>运单号</th><td><input type=\"text\" id=\"waybillNo\" value="+ data.content.waybillNo + "></td></tr>"
							+ "<tr><th>收货人详细地址</th><td><input type=\"text\" id=\"addres\" value="+ addres+ "></td></tr>"
							+ "<tr><th>省名称</th><td><input type=\"text\" id=\"provna\" value="+  data.content.provna+ "></td></tr>"
						    + "<tr><th>省编码</th><td><input type=\"text\" id=\"provco\" value="+   data.content.provco+ "></td></tr>"
							+ "<tr><th>市名称</th><td><input type=\"text\" id=\"cityna\" value="+   data.content.cityna+ "></td></tr>"
							+ "<tr><th>市编码</th><td><input type=\"text\" id=\"cityco\" value="+   data.content.cityco+ "></td></tr>"
							+ "<tr><th>区名称</th><td><input type=\"text\" id=\"distna\" value="+   data.content.distna+ "></td></tr>" 
							+ "<tr><th>区编码</th><td><input type=\"text\" id=\"distco\" value="+   data.content.distco+ "></td></tr>" 
							+ "<tr><th>邮编</th><td><input type=\"text\" id=\"postco\" value="+   data.content.postco+ "></td></tr>"
							+ "<tr><th>会员昵称</th><td><input type=\"text\" id=\"bunick\" value="+   data.content.bunick+ "></td></tr>"
							+ "<tr><th>收货人名称</th><td><input type=\"text\" id=\"recena\" value="+   data.content.recena+ "></td></tr>"
							+ "<tr><th>移动电话</th><td><input type=\"text\" id=\"mobile\" value="+   data.content.mobile+ "></td></tr>"
							+ "<tr><th>固定电话</th><td><input type=\"text\" id=\"teleph\" value="+   data.content.teleph+ "></td></tr>"
							+ "<tr><th>来源店铺名</th><td><input type=\"text\" id=\"shopna\" value="+   data.content.shopna+ "></td></tr>"
							+ "<tr><th>备注</th><td><input type=\"text\" id=\"ordenoMessage\" value="+   data.content.message+ "></td></tr>";
					$("#modalBodyOrders").html(tempString);
					$("#" + id).attr("href", "#ordersDetailed");
				} else if (data.status == "-1") {
					alert("还没有得到该订单的详细信息！");
				}
			},

			error :  function() {
				alert("还没有得到该订单的详细信息！");
			}
		});
	}
	
	function updateOrdenoItem(){
	var ordeno=$("#skuOrdeno").val();
	var sku=$("#skuSku").val();
	var storeCode=$("#skuStoreCode").val();
	var skuQty=$("#skuQty").val();
	var skuSiz=$("#skuSiz").val();
	  $.ajax({
			type :  'post',
			url :   '${ctx}/ediOrderSource/updateOrdenoItem',
			data :  'ordeno='+ordeno+'&sku='+sku+'&storeCode='+storeCode+'&skuQty='+skuQty+'&skuSiz='+skuSiz+'&id='+tempOrdenoItemId,
			dataType :  'json',
			success :  function(data) {
			    $("#message").show();
				$("#content").html(data.content);
				window.location.href = "${ctx}/ediOrderSource/searchCheck/"+$("#nowDate").val();
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	function getAjaxOrderItemsCheck(item) {
		var tempString = "";
	   $("#modalBodyOrderItems").html(tempString);
		
		ordenoId=item;
		$.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/getAjaxOrderItems',
			data :  'id=' + item,
			dataType :  'json',
			success :  function(data) {
				if (data.status == "1") {
					$.each(data.content,function(i){
					   normalIndex++;
					   tempString +="<input type=\"hidden\" id=\"normalId"+i+"\" value=\""+data.content[i].id+"\"><tr><td style=\"width: 150px;padding: 0px;height:  20px;\"><input style=\"width: 150px;margin: 0px;height:  20px;\" type=\"text\" id=\"normalOrdeno"+i+"\" value="+ data.content[i].ordeno + "></td>"
					        +"<td style=\"width: 150px;padding:  0px;height:  20px;\"><input style=\"width: 150px;margin: 0px;height:  20px;\" type=\"text\" id=\"normalWaybillNo"+i+"\" value="+ data.content[i].waybillNo+ "></td>"
							+"<td style=\"width: 150px;padding: 0px;height:  20px;\"><input style=\"width: 150px;margin: 0px;height:  20px;\" type=\"text\" id=\"normalStoreCode"+i+"\" value="+  data.content[i].storeCode+ "></td>"
						    + "<td style=\"width: 150px;padding: 0px;height:  20px;\"><input style=\"width: 150px;margin: 0px;height:  20px;\" type=\"text\" id=\"normalSku"+i+"\" value="+data.content[i].sku+ "></td>"
							+ "<td style=\"width: 150px;padding: 0px;height:  20px;\"><input style=\"width: 185px;margin: 0px;height:  20px;\" type=\"text\" id=\"normalQty"+i+"\" value="+data.content[i].qty+ "></td></tr>";
					});
				$("#modalBodyOrderItems").html(tempString);
					
					$("#" + oid).attr("href", "#orderItemsDetailed");
				} else {
					alert("还没有得到该订单的详细信息！");
				}
				
			},

			error :  function() {
				alert("还没有得到该订单的详细信息！");
			}
		});
	}
	
	function appendString(){
	  index++;
	  var tempString="<tr><td style=\"width: 150px;padding:  0px;height:  20px;\"><input type=\"text\" id=\"sku"+index+"\" style=\"width: 150px;margin: 0px;height:  20px;\"></td>"+
	                 "<td style=\"width: 150px;padding:  0px;height:  20px;\"><input type=\"text\" id=\"storeCode"+index+"\" style=\"width: 150px;margin: 0px;height:  20px;\"></td>"+
	                 "<td style=\"width: 150px;padding:  0px;height:  20px;\"><input type=\"text\" id=\"skuNumber"+index+"\" style=\"width: 185px;margin: 0px;height:  20px;\"></td></tr>";
	    $("#ordenoItems").append(tempString);
	}
	
	function getTrString(){
	  var indexString="";
	  for(var i=1;i<index+1;i++){
	     var sku= $("#sku"+i).val();
	     var storeCode= $("#storeCode"+i).val();
	     var skuNumber= $("#skuNumber"+i).val();
	     var ss=sku+"===paiu==="+storeCode+"===paiu==="+skuNumber;
	     if(""==indexString){
	       indexString=ss;
	     }else{
	        indexString+="---paiu---"+ss;
	     }
	  }
	  return indexString;
	}
	
	function inertsOrdenoItems(){
	
    	var skuString=getTrString();
    	  $.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/inertsOrdenoItems',
			data :  'skuString='+skuString+'&id='+ordenoId,
			dataType :  'json',
			success :  function(data) {
			    $("#message").show();
				$("#content").html(data.content);
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	function getOrdenoItems(){
	  var indexString="";
	  for(var i=0;i<normalIndex;i++){
	     var id=$("#normalId"+i).val();
	     var ordeno= $("#normalOrdeno"+i).val();
	     var waybillNo= $("#normalWaybillNo"+i).val();
	     var storeCode= $("#normalStoreCode"+i).val();
	     
	     var sku= $("#normalSku"+i).val();
	     var qty= $("#normalQty"+i).val();
	     var ss=id+"===paiu==="+ordeno+"===paiu==="+waybillNo+"===paiu==="+storeCode+"===paiu==="+sku+"===paiu==="+qty;
	     if(""==indexString){
	       indexString=ss;
	     }else{
	        indexString+="---paiu---"+ss;
	     }
	  }
	  return indexString;
	}
	
	function updateOrdenoItems(){
	
    	var ordenoItems=getOrdenoItems();
    	  $.ajax({
			type :  'post',
			url :  '${ctx}/ediOrderSource/updateOrdenoItems',
			data :  'ordenoItems='+ordenoItems+'&id='+ordenoId,
			dataType :  'json',
			success :  function(data) {
			    $("#message").show();
				$("#content").html(data.content);
			},

			error :  function() {
				alert("服务器错误！！！");
			}
		});
	}
</script>
	</head>

	<body>
	    <div id="message" class="alert alert-success" style="display:  none;">
			<span id="content"></span>
			
		</div>
		<div class="span8">
		<div class="input-prepend">
  <span class="add-on">检索订单日期</span>
  <input type="text" name="nowDate" id="nowDate"
			class="input-medium required" value="${nowDate}"
			style="margin-left:  10px;">
</div>
		</div>
		
			
			
			
		<div class="span12" style="margin-left:  -20px;">
			<div class="span6">
				<div class='label'
					style='font-size:  15px; padding:  3px;'>
					疑似订单列表 <span class="badge badge-important" id="ordenoNumber">${fn: length(exceptionOrdenos)}</span>
				</div>
				<table class="table table-striped table-bordered table-condensed">
					<thead>
						<tr>
							<th>
								订单号
							</th>
							<th>
								运单号
							</th>
						    <th>
								订单类型
							</th>
							<th>
								操作
							</th>

						</tr>
					</thead>
					<tbody id="noBoxCode">
						<c:forEach items="${exceptionOrdenos}" var="obj">
							<tr id="ordeno_${obj.id }">
								<td>
									${obj.ordeno}
								</td>
								<td>
									${obj.waybillNo}
								</td>
								<td>
								   <c:if test="${obj.forwardSign eq 'single' }">
								              <span class="badge badge-info">单件</span>
								   </c:if>
								    <c:if test="${obj.forwardSign eq 'multiple' }">
								            <span class="badge badge-warning">多件</span>
								   </c:if>
								    <c:if test="${obj.forwardSign eq 'forward' }">
								             <span class="badge badge-inverse">中转发</span>   
								   </c:if>
								</td>
								<td>
								   <a class="btn btn-danger" href="javascript: deleteOrdeno('${obj.id }');">删除</a>
								   
								  <c:if test="${obj.gymemo  ne 1 }">
								      <a href="#ordersDetailed" onclick="getAjaxOrdersCheck('${obj.id}')" role="button" class="btn btn-info" data-toggle="modal"> 
								    
								         修改
								      </a>
								  </c:if>
								   <c:if test="${obj.gymemo  eq 1 }">
								      <a href="#ordersDetailed" onclick="getAjaxOrdersCheck('${obj.id}')" role="button" class="btn" data-toggle="modal">订单详情 
								      </a>
								  </c:if>
								  
								  <c:if test="${obj.isspec eq -1 }">
								      <a href="#inertsOrdenoItems"  role="button" onclick="setOrdeno('${obj.id}')" class="btn btn-info" data-toggle="modal"> 插入商品 </a>
								     
								  </c:if>
								  <c:if test="${obj.isspec ne -1 }">
								   <a href="#orderItemsDetailed" onclick="getAjaxOrderItemsCheck('${obj.id}')" role="button" class="btn" data-toggle="modal"> 商品信息 </a>
								     
								  </c:if>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<div class="span6">
				<div class='label'
					style='font-size:  15px; padding:  3px;'>
					正常订单列表 <span class="badge badge-success" id="ordenoItemNumber">${fn: length(normalOrdenos)}</span>
				</div>
				<table class="table table-striped table-bordered table-condensed">
					<thead>
						<tr>
							<th>
								订单号
							</th>
							<th>
								运单号
							</th>
						    <th>订单类型</th>

							<th>
								操作
							</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${normalOrdenos}" var="obj">
							<tr id="ordenoItem_${obj.id }" width="27px;">
								<td width="10px;">
									${obj.ordeno}
								</td>
								<td width="10px;">
									${obj.waybillNo}
								</td>
								<td>
								   <c:if test="${obj.forwardSign eq 'single' }">
								              <span class="badge badge-info">单件</span>
								   </c:if>
								    <c:if test="${obj.forwardSign eq 'multiple' }">
								               <span class="badge badge-warning">多件</span>
								   </c:if>
								    <c:if test="${obj.forwardSign eq 'forward' }">
								             <span class="badge badge-inverse">中转发</span>    
								   </c:if>
								</td>
							
								<td>
                                   <a href="#ordersDetailed" onclick="getAjaxOrdersCheck('${obj.id}')" role="button" class="btn" data-toggle="modal"> 订单详情 </a>
                                   
								   <a href="#orderItemsDetailed" onclick="getAjaxOrderItemsCheck('${obj.id}')" role="button" class="btn" data-toggle="modal"> 记录详情 </a><!--
								   <a href="#inertsOrdenoItems"  role="button" onclick="setOrdeno('${obj.id}')" class="btn" data-toggle="modal"> 插入商品信息 </a>

								--></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
		<!-- 插入商品信息 -->
		<div style="display:  none;" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="inertsOrdenoItems">
			<div class="modal-header">
				<h3 id="myModalLabel">
					请输入商品信息
				</h3>
			</div>
			<div class="modal-body">
			<div onclick="appendString()" class="btn">新增商品列表</div>
				<table class="table table-striped table-bordered table-condensed">
				   <thead>
				     <th>编码</th>
				     <th>库位编码</th>
				     <th>数量</th>
				   </thead>
				   <tbody id="ordenoItems">
				   </tbody>
				</table>
			</div>
			<div class="modal-footer">
			    <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="inertsOrdenoItems()">
					插入
				</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					取消
				</button>
			</div>
		</div>
		
		<!-- 显示订单信息 -->    
		<div style="display:  none;" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="ordersDetailed">
			<div class="modal-header">
				<h3 id="myModalLabel">
					订单详细信息
				</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed"
					id="modalBodyOrders"></table>
			</div>
			<div class="modal-footer">
			    <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="updateOrdeno()">
					更新
				</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
		
		<!-- 显示商品记录信息 -->
		<div style="display:  none; width:  900px;" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="orderItemsDetailed">
			<div class="modal-header">
				<h3 id="myModalLabel">
					订单商品信息
				</h3>
			</div>
			<div class="modal-body" >
				<table class="table table-striped table-bordered table-condensed">
					  <thead>
					    <th>订单号</th>
					    <th>运单号</th>
					    <th>库位</th>
					    <th>SKU</th>
					    <th>数量</th>
					  </thead>
					  <tbody id="modalBodyOrderItems"></tbody>
					</table>
			</div>
			<div class="modal-footer">
			     <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="updateOrdenoItems()">
			    	更新
				</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
	</body>
</html>
